/*
 * author      : 吴中勤 
 * date        : 2018/8/16
 * description : moby事件分发, 此controller进行接收处理
 */

package com.deepexi.adapter.rest.sap;

import com.deepexi.adapter.facade.sap.SapPushService;
import com.deepexi.adapter.facade.sap.response.SapPushResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import static org.springframework.util.MimeTypeUtils.APPLICATION_JSON_VALUE;

@Controller
@RequestMapping(value = "/api/v1/sap-push")
public class SapSyncController {

    private static final Logger logger = LoggerFactory.getLogger(SapSyncController.class);

    @Autowired
    private SapPushService sapPushService;

    /** 测试接口 */
    @ResponseBody
    @RequestMapping(value = {"/ruok"}, method = {RequestMethod.GET})
    public String test1() throws Exception {
        logger.info("ruok");
        return "imok";
    }

    /** SAP物料 推送 */
    @ResponseBody
    @RequestMapping(method = {RequestMethod.POST}, value = {"/material"}, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
    public SapPushResponse onReceiveMaterial(@RequestBody String json) {
        logger.info("SAP物料 推送");

        sapPushService.onReceiveMaterial(json);
        return SapPushResponse.ALL_OK;
    }

    /** SAP车系 推送 */
    @ResponseBody
    @RequestMapping(method = {RequestMethod.POST}, value = {"/car-model-line"}, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
    public SapPushResponse onReceiveVehicleModelLine(@RequestBody String json) {
        logger.info("SAP车系 推送");
        sapPushService.onReceiveVehicleModelLine(json);
        return SapPushResponse.ALL_OK;
    }


    /** SAP车型 推送 */
    @ResponseBody
    @RequestMapping(method = {RequestMethod.POST}, value = {"/car-model"}, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
    public SapPushResponse onReceiveVehicleModel(@RequestBody String json) {
        logger.info("SAP车型 推送");
        sapPushService.onReceiveVehicleModel(json);
        return SapPushResponse.ALL_OK;
    }

    /** SAP内饰 推送 */
    @ResponseBody
    @RequestMapping(method = {RequestMethod.POST}, value = {"/car-interior"}, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
    public SapPushResponse onReceiveInteriorPart(@RequestBody String json) {
        logger.info("SAP内饰 推送");

        sapPushService.onReceiveInteriorPart(json);
        return SapPushResponse.ALL_OK;
    }

    /** SAP外观 推送 */
    @ResponseBody
    @RequestMapping(method = {RequestMethod.POST}, value = {"/car-appearance"}, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
    public SapPushResponse onReceiveExteriorPart(@RequestBody String json) {
        logger.info("SAP外观 推送");
        sapPushService.onReceiveExteriorPart(json);
        return SapPushResponse.ALL_OK;
    }

    /** 车辆信息 推送 */
    @ResponseBody
    @RequestMapping(method = {RequestMethod.POST}, value = {"/car-info"}, consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
    public SapPushResponse onReceiveVehicleInfo(@RequestBody String json) {
        logger.info("车辆信息 推送");
        sapPushService.onReceiveVehicleInfo(json);
        return SapPushResponse.ALL_OK;
    }

    /*
    # 物料数据导入 /api/v1/sap-old/materiel
    # 车辆数据导入 /api/v1/sap-old/car-info
    # 内饰数据导入 /api/v1/sap-old/car-interior
    # 外观数据导入 /api/v1/sap-old/car-appearance
    # 车系数据导入 /api/v1/sap-old/car-model-line
    # 车型数据导入 /api/v1/sap-old/car-model
    */
}
